/**
 * 全局过滤器
 */
Vue.filter('timeFilter', value => {
	var value = new Date(value);
	var year = value.getFullYear();
	var month = value.getMonth() + 1;
	var day = value.getDay();
	var hours = value.getHours();
	var minutes = value.getMinutes();
	var seconds = value.getSeconds();
	return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
})
/**
 * 自定义安检修饰符
 * Vue.config.keyCodes.名称=按键code码
 */
Vue.config.keyCodes.f2 = 113;

/**
 * 自定义全局指令:v-focus
 * binding:name：指令名，不包括 v- 前缀。
 * value：指令的绑定值，例如：v-my-directive="1 + 1" 中，绑定值为 2。
 * expression：字符串形式的指令表达式。例如 v-my-directive="1 + 1" 中，表达式为 "1 + 1"。
 */
Vue.directive('focus',{
	bind: function (el,binding) {
		// ...
	},
	inserted: function (el,binding) {
		el.focus();
	},
	update: function (el,binding) {
		
	}
})

var vm = new Vue({
	el: '#app',
	data: {
		title: '',
		id: '',
		keyWorld: '',
		list: [{
				id: 1,
				title: '01',
				time: new Date()
			},
			{
				id: 2,
				title: '02',
				time: new Date()
			}
		]
	},
	methods: {
		add: function() {
			this.list.push({
				id: this.id,
				title: this.title,
				time: new Date()
			});
			this.title = '';
			this.id = '';
		},
		search: function() {
			return this.list.filter(item => {
				if (item.title.indexOf(this.keyWorld) != -1) {
					return item;
				}
			});
		},
		remove: function(index) {
			this.list.splice(index, 1);
		}
	},
	// 局部过滤器
	filters: {
		timeFilter: function(date) {
			var value = new Date(date);
			var year = value.getFullYear();
			var month = (value.getMonth() + 1).toString().padStart(2,"0");
			var day = (value.getDay()).toString().padStart(2, "0");
			var hours = (value.getHours()).toString().padStart(2,"0");
			var minutes = (value.getMinutes()).toString().padStart(2,"0");
			var seconds = (value.getSeconds()).toString().padStart(2,"0");
			return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		}
	},
	directives: {
		focus:{// 全写
			bind: function (el,binding) {
				
			},
			inserted: function (el,binding) {
				
			},
			update: function (el, binding) {
				
			}
		},
		hello:function (el,binding) {// 简写
			
		}
	}
})
